﻿using System;

namespace KLS.PPDS.Utility.Extension
{
    public static class StringExtension
    {
        public static bool IsNullOrEmpty(this string value)
        {
            return string.IsNullOrWhiteSpace(value);
        }

        public static bool Contains(this string original, string value, StringComparison comparisionType)
        {
            return original.IndexOf(value, comparisionType) >= 0;
        }

     

        /// <summary>
        /// Trancate a string with the given lengh 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string Trancate(this string value, int length)
        {
            if (!value.IsNullOrEmpty())
            {
                return value.Length <= length ? value : value.Substring(0, length - 1) + "..";
            }
            else
            {
                return string.Empty;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string ReplaceSpecialCharecter(this string value)
        {
            if (!value.IsNullOrEmpty())
            { 
                //return value.Length <= length ? value : value.Substring(0, length - 1) + "..";
                return value.Replace(@"\", "-").Replace(@"/", "-").Replace(@":", "-").Replace(@":", "-").Replace(@"*", "-").Replace("\"", "-").Replace("?", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-").Replace(" ", "_");
            }
            else
            {
                return string.Empty;
            }
        }

        public static string ReplaceSpecialCharecterFileName(this string value)
        {
            if (!value.IsNullOrEmpty())
            {
                //return value.Length <= length ? value : value.Substring(0, length - 1) + "..";
                return value.Replace(@"\", "-").Replace(@"/", "-").Replace(@":", "-").Replace(@":", "-").Replace(@"*", "-").Replace("\"", "-").Replace("?", "-").Replace("<", "-").Replace(">", "-").Replace("|", "-");
            }
            else
            {
                return string.Empty;
            }
        }
    }
}
